package com.yugao.fintech.antelope.auth.controller;

import com.yugao.fintech.antelope.auth.model.rqrs.ldp.ExtLdpConnectResp;
import com.yugao.fintech.antelope.auth.model.rqrs.ldp.ExtLdpConnectSaveReq;
import com.yugao.fintech.antelope.auth.model.rqrs.ldp.ExtLdpConnectUpdateReq;
import com.yugao.fintech.antelope.auth.service.ExtLdpConnectService;
import com.yugao.fintech.antelope.base.ram.ActionType;
import com.yugao.fintech.antelope.base.ram.RamResource;
import com.yugao.fintech.framework.core.response.Resp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;

import java.util.List;

@RestController
@RequestMapping("/extLdpConnect")
@Api(tags = "外部身份源连接")
public class ExtLdpConnectController {
    @Autowired
    private ExtLdpConnectService ldpConnectService;

    @ApiOperation(value = "查询身份源连接")
    @GetMapping("/list")
    @RamResource(action = "auth:extLdpConnect:query", name = "查询外部身份源连接", type = ActionType.READ)
    public Resp<List<ExtLdpConnectResp>> listLdpConnect(@RequestParam("ldpId") Long ldpId) {
        return Resp.ok(ldpConnectService.listLdpConnect(ldpId));
    }
  
    @ApiOperation(value = "保存身份源连接")
    @PostMapping("/save")
    @RamResource(action = "auth:extLdpConnect:save", name = "保存外部身份源连接", type = ActionType.WRITE)
    public Resp<?> saveLdpConnect(@Validated @RequestBody ExtLdpConnectSaveReq req) {
        return Resp.ok(ldpConnectService.saveLdpConnect(req));
    }
  
    @ApiOperation(value = "更新身份源连接")
    @PostMapping("/update")
    @RamResource(action = "auth:extLdpConnect:update", name = "更新外部身份源连接", type = ActionType.WRITE)
    public Resp<?> updateLdpConnect(@Validated @RequestBody ExtLdpConnectUpdateReq req) {
        return Resp.ok(ldpConnectService.updateLdpConnect(req));
    }
  
    @ApiOperation(value = "删除身份源连接")
    @DeleteMapping("/delete")
    @RamResource(action = "auth:extLdpConnect:delete", name = "删除外部身份源连接", type = ActionType.WRITE)
    public Resp<?> deleteLdpConnect(@RequestParam(value = "id") Long id) {
        return Resp.ok(ldpConnectService.deleteLdpConnect(id));
    }

    /**
     * 获取外部身份源
     * @param clientId 客户端id
     */
    @GetMapping("/listByClientId")
    public Resp<List<ExtLdpConnectResp>> listByClientId(@RequestParam("clientId") String clientId) {
        return Resp.ok(ldpConnectService.listConnectByClientId(clientId));
    }
}
